package com.tsystems.tuni.sportplanet.entity;

import static javax.persistence.GenerationType.IDENTITY;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlTransient;

/**
 * Sport Entity.
 * 
 * @author Yuriy Eremin
 * 
 */
@Entity
@Table(name = "sport", catalog = "sportsplanet")
public class Sport implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Integer sportId;
	private String name;
	private Set<Team> teams = new HashSet<Team>(0);
	private Set<Game> games = new HashSet<Game>(0);

	public Sport() {
	}

	public Sport(String name) {
		this.name = name;
	}

	public Sport(Integer id, String name) {
		this.sportId = id;
		this.name = name;
	}

	public Sport(String name, Set<Team> teams, Set<Game> games) {
		this.name = name;
		this.teams = teams;
		this.games = games;
	}

	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "sport_id", unique = true, nullable = false)
	public Integer getSportId() {
		return this.sportId;
	}

	public void setSportId(Integer sportId) {
		this.sportId = sportId;
	}

	@Column(name = "name", nullable = false, length = 45)
	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@OneToMany(fetch = FetchType.LAZY, mappedBy = "sport")
	@XmlTransient
	public Set<Team> getTeams() {
		return this.teams;
	}

	public void setTeams(Set<Team> teams) {
		this.teams = teams;
	}

	@OneToMany(fetch = FetchType.LAZY, mappedBy = "sport")
	@XmlTransient
	public Set<Game> getGames() {
		return this.games;
	}

	public void setGames(Set<Game> games) {
		this.games = games;
	}

	@Override
	public String toString() {
		return name;
	}

}
